﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AG.Editor.Core;
using System.IO;

namespace AG.Editor.TextureFontUI.Windows
{
    public partial class AGCreateTextureFontWindow : Form
    {
        public AGTextureFont TextureFont { get; private set; }

        public AGCreateTextureFontWindow()
        {
            InitializeComponent();
        }

        private void _ctlBtnCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_ctlBtnBrowse.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(_ctlEditId.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(_ctlEditCaption.Text))
            {
                return;
            }

            try
            {
                TextureFont = new AGTextureFont();
                TextureFont.Id = Convert.ToInt32(_ctlEditId.Text);
                TextureFont.Caption = _ctlEditCaption.Text;

                // 拷贝材质文件到目录
                string fontsFolder = AGEContext.Current.EProject.GetFolderFonts();
                if (!Directory.Exists(fontsFolder))
                {
                    Directory.CreateDirectory(fontsFolder);
                }

                FileInfo fileInfo = new FileInfo(_ctlBtnBrowse.Text);
                File.Copy(fileInfo.FullName, string.Format("{0}\\{1}", fontsFolder, fileInfo.Name), true);
                TextureFont.TextureFile = fileInfo.Name;

                AGTools.Current.TextureFontStore.SaveTextureFont(AGEContext.Current.EProject, TextureFont);

                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch
            {
            }
        }

        private void _ctlBtnBrowse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _ctlBtnBrowse.Text = dlg.FileName; ;
            }
        }
    }
}
